<template>
  <div>
    <div class="header">
      <div class="same">
        <!-- <Position /> -->
        <div class="hed">
          <div class="til">
            <!-- <div class="address_map">
              <i class="el-icon-location-information"></i>
              <span>{{ address }}</span>
              <i class="el-icon-arrow-down"></i>
            </div> -->
            <Position class="address_map" />
            <h2>萌宠乐园</h2>
          </div>
          <div class="sousuo">
            <i class="el-icon-search"></i>
            <input type="text" placeholder="请搜索商品/医院" />
          </div>
        </div>
      </div>
    </div>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <div class="main">
        <CommBtn class="Commbtn" />
        <div class="same">
          <div class="pet" v-if="pats.length == 0">
            <div class="pet-img">
              <img
                src="https://tse1-mm.cn.bing.net/th/id/R-C.2ef794f96f679089ebb01f4ce6b2da87?rik=1Dqp8juCKh3rKw&riu=http%3a%2f%2fimg.ewebweb.com%2fuploads%2f20200303%2f18%2f1583232918-ilkpCfSLwK.jpeg&ehk=L8EDSWDAtKMlaIKW4ET9sSlFxqRTtGd9HmzNYqM52kw%3d&risl=&pid=ImgRaw&r=0"
                alt=""
              />
            </div>
            <p>添加宠物,开启TA的专属健康管理计划</p>
            <button @click="AddPats">
              {{ $store.state.token == "" ? "请登录" : "添加宠物" }}
            </button>
          </div>
          <div
            v-show="i === index"
            class="pet"
            v-else
            v-for="(pat, i) in pats"
            :key="pat.idnumber"
          >
            <div class="pet-img">
              <img
                src="https://tse1-mm.cn.bing.net/th/id/R-C.2ef794f96f679089ebb01f4ce6b2da87?rik=1Dqp8juCKh3rKw&riu=http%3a%2f%2fimg.ewebweb.com%2fuploads%2f20200303%2f18%2f1583232918-ilkpCfSLwK.jpeg&ehk=L8EDSWDAtKMlaIKW4ET9sSlFxqRTtGd9HmzNYqM52kw%3d&risl=&pid=ImgRaw&r=0"
                alt=""
              />
            </div>
            <div class="patsInfo">
              <div class="left">
                <dl>
                  <dt>
                    {{ pat.petsname }}
                    <i
                      :class="
                        pat.petssex == 1 ? 'el-icon-male' : 'el-icon-female'
                      "
                    ></i>
                  </dt>
                  <dd>{{ pat.petstype }}</dd>
                  <dd>{{ pat.petssex == 1 ? "男孩子" : "女孩子" }}></dd>
                </dl>
              </div>
              <div class="right">
                <dl>
                  <dt>健康管理</dt>
                  <dd>宠物全年健康管理服务</dd>
                  <dd>添加宠物 ></dd>
                </dl>
              </div>
            </div>
          </div>

          <div class="nav">
            <router-link to="/hospital_lists">
              <dl>
                <i>
                  <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icon-guahao1"></use>
                  </svg>
                </i>
                <dt>预约挂号</dt>
              </dl>
            </router-link>
            <dl>
              <i>
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-yuyue"></use>
                </svg>
              </i>
              <dt>预约洗美</dt>
            </dl>
            <dl>
              <i>
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-zaixianwenzhen-01"></use>
                </svg>
              </i>
              <dt>医疗专区</dt>
            </dl>
            <dl>
              <i>
                <svg class="icon" aria-hidden="true">
                  <use xlink:href="#icon-yiliao"></use>
                </svg>
              </i>
              <dt>洗美专区</dt>
            </dl>
          </div>
          <div class="swipersame">
            <div class="swiper mySwiper">
              <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="item in banner" :key="item.id">
                  <img :src="item.img" alt="" />
                </div>
              </div>
            </div>
          </div>
          <div class="recommend">
            <div class="til">
              <h2>优质推荐</h2>
            </div>
            <van-empty
              v-show="recommend.length == 0"
              image="network"
              description="网络错误"
            />
            <div class="row">
              <div
                v-show="recommend.length !== 0"
                class="box"
                v-for="item in recommend"
                :key="item.id"
              >
                <router-link :to="'/detail/' + item.id">
                  <!-- <img :src="item.img" alt="" /> -->
                  <img
                    :src="`http://192.168.10.23:8888/` + item.shopImg"
                    alt=""
                  />
                  <dl>
                    <dt>{{ item.shopName }}</dt>
                    <dd>￥{{ item.shopPrice }}</dd>
                  </dl>
                </router-link>
              </div>
            </div>
          </div>
        </div>
      </div>
    </van-pull-refresh>
  </div>
</template>
<script>
import Position from "../../components/Position.vue";
import Swiper from "swiper";
import "@/iconfont/iconfont.js";
import "../../../node_modules/swiper/css/swiper.css";
import CommBtn from "../../components/CommBtn.vue";
import { shopAll, selectpet } from "@/api/index";
import { Toast } from "vant";

export default {
  components: {
    Position,
    CommBtn,
  },
  data() {
    return {
      index: 0,
      isLoading: false,
      banner: [
        {
          id: 1,
          img: "https://img.zcool.cn/community/0161fa5d9c507ca8012060beab8251.jpg@1280w_1l_2o_100sh.jpg",
        },
        {
          id: 2,
          img: "https://img.zcool.cn/community/0163a15bae2992a8012099c87d9f4a.png@2o.png",
        },
        {
          id: 3,
          img: "https://cbu01.alicdn.com/img/ibank/2020/551/398/22265893155_1262084193.jpg",
        },
        {
          id: 4,
          img: "https://cbu01.alicdn.com/img/ibank/2019/679/188/10746881976_1262084193.jpg",
        },
        {
          id: 5,
          img: "https://img.zcool.cn/community/01b6295e078c83a801216518404d2f.jpg@1280w_1l_2o_100sh.jpg",
        },
      ],
      recommend: [],
      pats: [],
    };
  },

  mounted() {
    new Swiper(".mySwiper", {
      autoplay: true,

      loop: true,
    });
  },
  created() {
    this.shopTuijian();
    this.selectpet();
  },
  methods: {
    AddPats() {
      if (this.$store.state.token == "") {
        Toast("请先登录");
        this.$router.push("/login");
      } else {
        this.$router.push("/pats");
      }
    },
    selectpet() {
      let id = this.$store.state.user.id;
      selectpet(id).then((res) => {
        // console.log(res);
        this.pats = res.data.data;
      });
    },
    shopTuijian() {
      shopAll().then((res) => {
        // console.log(res.data.data);
        this.recommend = res.data.data;
      });
    },

    onRefresh() {
      setTimeout(() => {
        Toast("刷新成功");
        this.shopTuijian();
        this.isLoading = false;
      }, 1000);
    },
  },
};
</script>
<style scoped lang="scss">
.Commbtn {
  position: fixed;
  right: 15px;
  bottom: 20vh;
  z-index: 10;
}
.header {
  width: 100%;
  height: 20vh;
  display: flex;
  background: transparent;
  z-index: 5;
  top: 0;
  position: fixed;
  background-image: linear-gradient(120deg, #f6d365 0%, #fda085 100%);
  .hed {
    width: 100%;
    height: 16vh;
    .til {
      width: 100%;
      height: 10vh;
      display: flex;
      align-items: center;
      // justify-content: center;
      .address_map {
        display: flex;
        align-items: center;
        width: 37%;
        height: 10vh;
        // background: red;
        margin-right: 10px;
      }
      h2 {
        font-weight: normal;
        font-size: 18px;
      }
    }
    .sousuo {
      width: 100%;
      height: 5vh;
      // background: cadetblue;
      display: flex;
      align-items: center;
      position: relative;

      input {
        width: 100%;
        height: 5vh;
        border-radius: 20px;
        text-indent: 2em;
        outline: none;
        border: 0;
      }
      input:hover {
        border: 1px solid orange;
      }
      i {
        position: absolute;
        left: 10px;
      }
    }
  }
}
.main {
  width: 100%;
  height: auto;
  background: #eeeeeea8;
  margin-bottom: 10vh;
  margin-top: 22vh;
  overflow: hidden;
  .swipersame {
    width: 100%;
    overflow: hidden;
    border-radius: 10px;
    .swiper-slide {
      img {
        width: 100%;
        height: 22vh;
      }
    }
  }
  .nav {
    width: 100%;
    height: 10vh;
    margin: 2vh 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    a {
      color: #000;
    }
    dl {
      width: 20vw;
      height: 10vh;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      // background: cyan;
      i {
        font-size: 26px;
        margin-bottom: 1vh;
      }
    }
  }
  .pet {
    width: 100%;
    height: 25vh;
    // background: rgb(255, 255, 255);
    margin-top: 5vh;
    border-radius: 10px;
    text-align: center;
    position: relative;
    background: url("https://tse1-mm.cn.bing.net/th/id/R-C.3da8c021a51d9704f02b2a85b8e7c68d?rik=yzzN33I%2fqKrfew&riu=http%3a%2f%2fpic.51yuansu.com%2fbackgd%2fcover%2f00%2f04%2f18%2f5b5edcfd0ee4b.jpg!%2ffw%2f780%2fquality%2f90%2funsharp%2ftrue%2fcompress%2ftrue&ehk=%2bvdn50hyLxGEV9O5dT4XiVTc3TvBMgWDGp4oBELiZJ8%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1")
      no-repeat;
    background-size: 100% 100%;
    opacity: 0.95;
    .patsInfo {
      width: 100%;
      height: 15vh;
      display: flex;
      align-items: center;
      justify-content: space-around;
      color: rgb(0, 0, 0);
      .left {
        width: 40%;
        height: 15vh;
        background: rgba($color: #ffffff, $alpha: 0.5);
        dl {
          text-align: left;
          line-height: 4vh;
          color: #333;
          margin-left: 5vh;
        }
      }
      .right {
        width: 45%;
        height: 15vh;
        padding-left: 10px;
        border-left: 1px solid #ccc;
        background: rgba($color: #ffffff, $alpha: 0.5);

        dl {
          text-align: left;
          line-height: 4vh;
          color: #333;
        }
      }
    }
    .pet-img {
      position: relative;
      height: 10vh;
      img {
        height: 10vh;
        border-radius: 50%;
        position: absolute;
        top: -26px;
        left: 50%;
        transform: translateX(-5vh);
      }
    }

    p {
      height: 5vh;
    }
    button {
      width: 40vw;
      height: 6vh;
      border: 0;
      border-radius: 20px;
      color: rgb(255, 180, 20);
      background: rgb(14, 14, 14);
    }
  }
  .recommend {
    width: 100%;
    height: auto;
    margin-top: 3vh;
    background: rgba(255, 255, 255, 0.308);
    border-radius: 10px;
    .til {
      height: 5vh;
      // background: red;
      line-height: 5vh;
      h2 {
        font-weight: normal;
        font-size: 20px;
        margin-left: 2vw;
      }
    }
    .row {
      width: 100%;
      height: auto;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .box {
        width: 48%;
        height: 36vh;
        background: rgb(255, 255, 255);
        border-radius: 10px;
        margin-bottom: 2vh;
        overflow: hidden;
        img {
          width: 100%;
          height: 20vh;
        }
        dl {
          width: 95%;
          font-size: 14px;
          margin: 0 auto;
          dt {
            color: #333;
            height: 6vh;
            overflow: hidden;
            margin: 2vh 0;
          }
          dd {
            color: rgb(211, 92, 23);
            position: relative;
            del {
              position: absolute;

              font-size: 12px;
              color: #aaa;
            }
          }
        }
      }
    }
  }
}
</style>
